<template>
  <div class="app-container">
    <div class="page-filter mb10 fl">
      <el-form ref="filter" :model="filter" label-width="0">
        <el-form-item class="mr10 mb5 fl" style="width: 300px">
          <el-button size="small" @click="app.resetFields($refs['filter'].$parent,'filter')">清 空</el-button>
          <el-button type="primary" size="small" @click="getList">查 询</el-button>
        </el-form-item>
      </el-form>
    </div>
    <el-table ref="multipleTable" class="search-table" :data="list" border fit highlight-current-row style="width: 100%;">
      <el-table-column label="序号" align="center" width="56px">
        <template slot-scope="{$index}">
          {{ $index + 1 }}
        </template>
      </el-table-column>
      <el-table-column label="项目名称" width="220px" prop="pro_name" />
      <el-table-column label="PO单号" width="190px">
        <template slot-scope="{row}">
          <span v-if="row.pro_id !== ''">{{ 'PO'+row.pro_id }}</span>
        </template>
      </el-table-column>
      <el-table-column label="待办类型" width="110px" prop="type" />
      <el-table-column label="发起人" width="120px" prop="initiator_name" />
      <el-table-column label="接收人" width="120px" prop="receiver_name" />
      <el-table-column label="状态" align="center" width="90px" prop="state" :formatter="formatterState"/>
      <el-table-column label="计划开始时间" align="center" width="110px" prop="begin_time" />
      <el-table-column label="计划完成时间" align="center" width="110px" prop="plan_time" />
      <el-table-column label="实际完成时间" align="center" width="160px" prop="actual_time" />
      <el-table-column label="备注" min-width="260px" prop="remark" />
      <el-table-column label="操作" align="center" width="110px" fixed="right">
        <template slot-scope="{row}">
          <el-dropdown>
            <el-button type="primary" size="mini">
              操作<i class="el-icon-arrow-down el-icon--right"></i>
            </el-button>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item
                @click.native="handleDialog({...row, ...
                {dTitle: '处理待办', dType: 'view', dField: dField}})"
              >处 理</el-dropdown-item>
              <el-dropdown-item
                @click.native="handleFinish(row)"
              >完 成</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="filter.pageAll>0" :total="filter.pageAll" :page.sync="filter.pageCurrent" :limit.sync="filter.pageNumber" @pagination="getList" />
    <Cos ref="cos" :info="dialog" />
    <Dialog ref="dialog" :get-data="getList" :info="dialog" />
  </div>
</template>

<script>
import { myAgents, updAgent } from '@/api/agent/agent'
import Dialog from './components/agent-handle-dialog'
import page from '@/utils/page'

export default {
  name: '',
  components: { Dialog },
  extends: page,
  props: {
    reqList: {
      default: myAgents,
      type: Function
    }
  },
  data() {
    return {
      parameter: { active: '0' },
      dField: ['id', 'pro_id', 'remark', 'type', 'receiver_id', 'begin_time', 'plan_time', 'matters']
    }
  },
  created() {
    this.getList()
  },
  methods: {
    formatterState(e) {
      if (e.state === 0) {
        return '未完成'
      } else if (e.state === 1) {
        return '已完成'
      } else {
        return '进行中'
      }
    },
    handleFinish(e) {
      this.$confirm('此操作将修改数据信息，数据将无法恢复, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(async() => {
        updAgent({
          state: '1',
          id: e.id
        }).then(response => {
          this.getList()
        }).catch(err => {
          this.$message.error(err.msg)
        })
      })
    }
  }
}
</script>
